import os


def dowloadM3U8File(src: str):
  rfile = open(src, encoding='utf-8').readlines()
  # for index, command in enumerate(rfile, 1):
  # if index <= 17:
  # continue
  for command in rfile:
    if command.startswith("//"):
      continue
    print(command)
    os.system(command)


def basic_downloader(url: str, name: str):
  command = f'ffget {url} --no-log --save-dir f:\\temp --save-name {name}'
  info = os.system(command)
  print(info)


def downloadM3U8TPL(tpl: str):
  lines = open(tpl, encoding='utf-8').readlines()
  line = lines.pop()
  if line.startswith('//'):
    line = lines.pop()

  for i in range(39, 41):
    if i < 10:
      command = line.replace('{0}', '0' + str(i))
    else:
      command = line.replace('{0}', str(i))
    print(command)
    os.system(command)


if __name__ == '__main__':
  # downloadM3U8TPL('../resources/zt.url')
  # downloadM3U8TPL('../resources/xn.url')
  # dowloadM3U8File('../resources/frxxz1.url')
  dowloadM3U8File('../resources/list.url')
  # basic_downloader("https://vip.ffzy-play2.com/20230427/46241_e72cbca5/index.m3u8", '天下无双')
  # basic_downloader("https://vip1.lz-cdn1.com/20220405/1115_52e4d1b6/1200k/hls/mixed.m3u8", '火舞风云')
